package com.renfei.ffmpegproject.act;

import android.os.Bundle;
import android.os.Environment;
import android.util.Log;
import android.widget.TextView;

import com.renfei.ffmpegproject.Player.MinePlayer;
import com.renfei.ffmpegproject.R;
import com.renfei.ffmpegproject.base.BaseActivity;
import com.renfei.ffmpegproject.bean.MineTimeInfo;
import com.renfei.ffmpegproject.listener.MineOnParparedListener;
import com.renfei.ffmpegproject.listener.MineOnTimeInfoListener;
import com.renfei.ffmpegproject.listener.OnPcmDataCallBackListener;

import java.io.File;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

public class CutAudioActivity extends BaseActivity {

    private static final String TAG = "CutAudioActivity";
    @BindView(R.id.tv_cut_audio)
    TextView tvCutAudio;
    @BindView(R.id.tv_pause)
    TextView tvPause;
    @BindView(R.id.tv_resume)
    TextView tvResume;
    @BindView(R.id.tv_stop)
    TextView tvStop;

    private MinePlayer minePlayer;
    @Override
    protected int getLayoutId() {
        return R.layout.activity_cut_audio;
    }

    @Override
    protected void initListener() {
        minePlayer=new MinePlayer();
        minePlayer.setMineOnParparedListener(new MineOnParparedListener() {
            @Override
            public void onParpared() {
                minePlayer.cutAudioPlay(10,40,true);
            }
        });
        minePlayer.setMineOnTimeInfoListener(new MineOnTimeInfoListener() {
            @Override
            public void onTimeInfo(MineTimeInfo timeInfo) {
                loge("CutAudioActivity",timeInfo.toString());
            }
        });
        minePlayer.setOnPcmDataCallBackListener(new OnPcmDataCallBackListener() {
            @Override
            public void onPcmCallBack(byte[] data, int len) {
                Log.e(TAG, "onPcmCallBack: "+len);
            }

            @Override
            public void onPcmRate(int sampleRate, int bit, int channel) {
                Log.d(TAG, "onPcmRate: "+sampleRate);
            }
        });
    }

    @OnClick(R.id.tv_cut_audio)
    public void onViewClicked() {

        String parentPath = Environment.getExternalStorageDirectory().getPath();
        loge("parentPath", parentPath);
        File file = new File(parentPath + "/the_girl.m4a");
        if (!file.exists()){
            return;
        }
        minePlayer.setSource(file.getPath());
        minePlayer.parpared();
    }
}
